package com.ruoyi.restaurant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.restaurant.domain.ItemOrder;
import com.ruoyi.restaurant.service.IItemOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐品项目—订单Controller
 * 
 * @author ruoyi
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/itemOrder/show")
public class ItemOrderController extends BaseController
{
    @Autowired
    private IItemOrderService itemOrderService;

    /**
     * 查询餐品项目—订单列表
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemOrder itemOrder)
    {
        startPage();
        List<ItemOrder> list = itemOrderService.selectItemOrderList(itemOrder);
        return getDataTable(list);
    }

    /**
     * 导出餐品项目—订单列表
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:export')")
    @Log(title = "餐品项目—订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemOrder itemOrder)
    {
        List<ItemOrder> list = itemOrderService.selectItemOrderList(itemOrder);
        ExcelUtil<ItemOrder> util = new ExcelUtil<ItemOrder>(ItemOrder.class);
        util.exportExcel(response, list, "餐品项目—订单数据");
    }

    /**
     * 获取餐品项目—订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:query')")
    @GetMapping(value = "/{iId}")
    public AjaxResult getInfo(@PathVariable("iId") Integer iId)
    {
        return AjaxResult.success(itemOrderService.selectItemOrderByIId(iId));
    }

    /**
     * 新增餐品项目—订单
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:add')")
    @Log(title = "餐品项目—订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemOrder itemOrder)
    {
        return toAjax(itemOrderService.insertItemOrder(itemOrder));
    }

    /**
     * 修改餐品项目—订单
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:edit')")
    @Log(title = "餐品项目—订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemOrder itemOrder)
    {
        return toAjax(itemOrderService.updateItemOrder(itemOrder));
    }

    /**
     * 删除餐品项目—订单
     */
    @PreAuthorize("@ss.hasPermi('itemOrder:show:remove')")
    @Log(title = "餐品项目—订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iIds}")
    public AjaxResult remove(@PathVariable Integer[] iIds)
    {
        return toAjax(itemOrderService.deleteItemOrderByIIds(iIds));
    }
}
